import "./src/main.scss";
import SvgIcon from "@/components/svg-icon/index.vue";
import { h } from "vue";
import { ElMessage } from "element-plus";
const Message: any = function (options: any) {
  ElMessage.closeAll();
  options = options || {};
  if (typeof options === "string") {
    options = {
      message: options
    };
  }
  options = Object.assign({}, options, {
    customClass: [
      "ps-message-box",
      options.offset ? "" : "tCenter",
      options.center ? "is-center" : "",
      options.type || options.icon ? "has-svg" : "",
      options.type ? options.type : "",
      options.operate ? "operate-message" : "",
      "nowrap",
      options.customClass
    ]
      .filter((it) => it)
      .join(" ")
  });
  return ElMessage(options);
};

["success", "warning", "info", "error"].forEach((type) => {
  Message[type] = (options: any) => {
    if (typeof options === "string") {
      options = {
        message: options
      };
    }
    options.type = type;
    options.icon = h(SvgIcon, {
      iconClass: type
    });
    return Message(options);
  };
});

Message.closeAll = function () {
  ElMessage.closeAll();
};

export default Message;
